from pathlib import Path, PurePath
from .utils import filename_split

class Store:
    def __init__(self, dbpath=Path('./articles')):
        self._dbpath = dbpath
        self._entries = [x for x in Path(dbpath).iterdir() if PurePath(x).match('*.txt')]

    def list(self):
        def gen(idx, entry):
            info = filename_split(PurePath(entry).name)
            info['id'] = idx
            return info
        return [gen(idx, entry) for idx, entry in enumerate(self._entries)]
